﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading;

namespace Ahi
{
    public partial class Splasher : DevExpress.XtraEditors.XtraForm
    {
        private static Splasher _instance;
        public static Splasher Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new Splasher();
                return _instance;
            }
        }

        private List<Action> _workList = new List<Action>();
        public List<Action> WorkList { get { return _workList; } }

        private Splasher()
        {
            InitializeComponent();
        }

        public void SetProgress(string description)
        {
            if (!string.IsNullOrEmpty(description))
            {
                if (label1.InvokeRequired)
                    label1.Invoke((MethodInvoker)delegate()
                    {
                        label1.Text = description;
                        label1.Refresh();
                    });
                else
                {
                    label1.Text = description;
                    label1.Refresh();
                }
            }

            if (progressBar1.InvokeRequired)
                progressBar1.Invoke((MethodInvoker)delegate()
                {
                    progressBar1.Value++;
                });
            else
                progressBar1.Value++;
        }

        public void StartSplashAndWork()
        {
            progressBar1.Maximum = _workList.Count + 3;

            this.Show();

            foreach (var item in _workList)
            {
                item.Invoke();
            }

            SetProgress("Uygulama hazırlandı.");
            Thread.Sleep(100);

            this.Close();
        }
    }
}
